package utils

import (
	"reflect"
	errors2 "server/framework/orm/errors"
)

// ValidateValsType vals 需要是指向切片的指针,切片元素需要是指向结构体的指针
func ValidateValsType(vals interface{}) (elem reflect.Type, err error) {
	typ := reflect.TypeOf(vals)
	if typ.Kind() != reflect.Pointer || typ.Elem().Kind() != reflect.Slice {
		err = errors2.ErrNotSlicePtr
	}
	typ = typ.Elem()  // 切片
	elem = typ.Elem() // 获取元素
	if elem.Kind() != reflect.Pointer || elem.Elem().Kind() != reflect.Struct {
		err = errors2.ErrNotPointToStruct
	}
	elem = elem.Elem()
	return
}
